
#ifndef _RTT_PRINT_H_
#define _RTT_PRINT_H_
#ifdef __cplusplus
 extern "C" {
#endif
// #define printf PRINT_INFO
#include <Arduino.h>

#ifdef SEGGER_RTT_EN
#include <SEGGER_RTT.h>
#include <SEGGER_RTT_Conf.h>
 #define printf PRINT_RAW
// #undef BUFFER_SIZE_UP
// #define BUFFER_SIZE_UP 256

#define BDS_COLOR_TAG "BDSCOL"
#define BDS_LOG_COLOR_BLACK 0x000000  // 黑色
#define BDS_LOG_COLOR_RED 0xFF3030    // 红色
#define BDS_LOG_COLOR_GREEN 0x008B00  // 绿色
#define BDS_LOG_COLOR_BLUE 0x00008B   // 蓝色
#define BDS_LOG_COLOR_VIOLET 0x9932CC // 紫色

#define ERROR_COLOR (String("BDSCOL(") + String(BDS_LOG_COLOR_RED) + String(")")).c_str()
#define DEBUG_COLOR (String("BDSCOL(") + String(BDS_LOG_COLOR_GREEN) + String(")")).c_str()
#define INFO_COLOR  (String("BDSCOL(") + String(BDS_LOG_COLOR_BLUE) + String(")")).c_str()

// #define ERROR_COLOR RTT_CTRL_TEXT_BRIGHT_RED
// #define DEBUG_COLOR RTT_CTRL_TEXT_GREEN
// #define INFO_COLOR  RTT_CTRL_TEXT_WHITE

#define PRINT_ERROR(...)                                                      \
    SEGGER_RTT_WriteString(0, ERROR_COLOR);                                   \
    SEGGER_RTT_printf(0, "error[%s][%s][%d]:", __FILE__, __func__, __LINE__); \
    SEGGER_RTT_printf(0, ##__VA_ARGS__);
#ifdef DEBUG_EN
#define PRINT_DEBUG(...)                                                      \
    SEGGER_RTT_WriteString(0, DEBUG_COLOR);                                   \
    SEGGER_RTT_printf(0, "debug[%s][%s][%d]:", __FILE__, __func__, __LINE__); \
    SEGGER_RTT_printf(0, ##__VA_ARGS__);
#else
#define PRINT_DEBUG(...) ((void)0)
#endif
#define PRINT_INFO(...)                    \
    SEGGER_RTT_WriteString(0, INFO_COLOR); \
    SEGGER_RTT_printf(0, "info:");         \
    SEGGER_RTT_printf(0, ##__VA_ARGS__);
#define PRINT_RAW(...) \
    SEGGER_RTT_printf(0, ##__VA_ARGS__);

// #define printf PRINT_INFO
#else
#define PRINT_ERROR(...) ((void)0)
#define PRINT_DEBUG(...) ((void)0)
#define PRINT_INFO(...) ((void)0)
#define PRINT_RAW(...) ((void)0)
#define printf PRINT_RAW
#endif
#ifdef __cplusplus
}
#endif
#endif
